#include<stdio.h>
#include<mysql/mysql.h>
#include<string.h>
#include "sql.h"

int mysql_connect(MYSQL &mysql){
	mysql_init(&mysql);

	mysql_options(&mysql,MYSQL_SET_CHARSET_NAME,"gbk");

	MYSQL *ret = mysql_real_connect(&mysql,_HOST_,_USER_,_PWD_,_DB_,3306,NULL,0);
	if(ret==NULL){
		printf("mysql connect failed %s \n",mysql_error(&mysql));
		return 1;
	}
	
	int res = mysql_select_db(&mysql,_DB_);
	if(res){
		printf("database select failed \n");
		return 2;
	}

	return 0;
}


